/*
* Copyright (C) 2012-2014 qar
* License: http://www.gnu.org/licenses/gpl.html GPL version 2
*/

#ifndef UTIL_H
#define UTIL_H

#include <QtCore>

#define ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop())

// Returns the current time, measured in milliseconds since the epoch.
qint64 currentMSecsSinceEpoch();

// Returns the current time, measured in nanoseconds since the epoch.
qint64 currentNanoSecsSinceEpoch();

// Retrieves the target of a link. The result is relative to the link.
QString getLinkTarget(QString link);

// Retrieves the parent directory from a path (removes the last part after /).
QString getParentDir(QString path);

// Adds a K/M/G/T prefix to the value in bytes, updating value for the new prefix and saving
// the prefix in the @prefix variable.
void addSizePrefix(qint64 &value, QString &prefix);

// Displays the progress to the console (speed, current action etc).
void displayProgress(QString currentItem,
                     qint64 currentProgressBytes,
                     qint64 startTime,
                     qint64 &lastProgressTime,
                     qint64 &lastProgressBytes,
                     const QIODevice *archiveFile = NULL);

int getTerminalWidth(int fd);

#endif // UTIL_H
